<?php
	if ($current_day <= 7) {
		if ($month == 1) {
			$temp_month = 12;
			$temp_year = $year - 1;
		}
		else {
			$temp_month = $month - 1;
			$temp_year = $year;
		}
		$prev_month_offset = cal_days_in_month(0, $temp_month, $year);
		$temp_day = ($current_day - 7) + $prev_month_offset;	
	}
	else {
		$temp_day = $current_day - 7;
		$temp_month = $month;
		$temp_year = $year;
	}
?>

<a href="viewWeek.php?day=<?php echo $temp_day ?>&month=<?php echo $temp_month ?>&year=<?php echo $temp_year ?>">&lt;</a> 

<?php 
	$temp_stamp = mktime(0,0,0,$month,$current_day,$year);
	$week = date('W', $temp_stamp);
	echo "<span class='dateheader'>$year : Week $week</span>"; 

?>

<?php
	$month_days = cal_days_in_month(0, $month, $year);
	if ($current_day + 7 >= $month_days) {
		$temp_day = ($current_day + 7) - $month_days;
		if ($month == 12) {
			$temp_month = 1;
			$temp_year = $year + 1;
		}
		else {
			$temp_month = $month + 1;
			$temp_year = $year;
		}
	}
	else {
		$temp_day = $current_day + 7;
		$temp_month = $month;
		$temp_year = $year;
	}
?>

<a href="viewWeek.php?day=<?php echo $temp_day ?>&month=<?php echo $temp_month ?>&year=<?php echo $temp_year ?>">&gt;</a> 